#!/usr/bin/python

from rule_manager import Rule_manager

class Numbers_changer:
  def __init__(self):
    self.ruleManager = Rule_manager()
    self.attributeNames = { "subst" : "fleks",
                            "num" : "fleks",
                            "numcol" : "fleks",
                            "adj" : "fleks",

                            "sg" : "liczba",
                            "pl" : "liczba",

                            "nom" : "przypadek",
                            "gen" : "przypadek",
                            "dat" : "przypadek",
                            "acc" : "przypadek",
                            "inst" : "przypadek",
                            "loc" : "przypadek",
                            "voc" : "przypadek",

                            "m1" : "rodzaj",
                            "m2" : "rodzaj",
                            "m3" : "rodzaj",
                            "f" : "rodzaj",
                            "n" : "rodzaj",

                            "pri" : "osoba",
                            "sec" : "osoba",
                            "ter" : "osoba",

                            "pos" : "stopien",
                            "comp" : "stopien",
                            "sup" : "stopien",

                            "imperf" : "aspekt",
                            "perf" : "aspekt",

                            "aff" : "negacja",
                            "neg" : "negacja",

                            "akc" : "akcent",
                            "nakc" : "akcent",

                            "praep" : "poprzyimkowsc",
                            "npraep" : "poprzyimkowsc",

                            "congr" : "akomodacyjnosc",
                            "rec" : "akomodacyjnosc",

                            "agl" : "aglutynacja",
                            "nagl" : "aglutynacja",

                            "wok" : "wokalicznosc",
                            "nwok" : "wokalicznosc" }

  def change_old(self, number, tags):
    if self.isNumber(number) == False:
      return number
    
    strNumber = number
    number = float(strNumber)
    tags = tags.split(":")

    if number < 20:
      return self.getCorrectForm(number, tags)
    
    elif number < 100:
      deci = int(strNumber[0]+"0")
      rest = strNumber[1]

      if rest == "0":
        return self.getCorrectForm(deci, tags)
      else:
        return self.getCorrectForm(deci, tags) + " " + self.change(rest, tags)
      
    elif number >= 100 and number < 1000:
      hund = int(strNumber[0]+"00")
      rest = strNumber[1:]
      
      if rest == "00":
        return self.getCorrectForm(hund, tags)
      else:
        return self.getCorrectForm(hund, tags) + " " + self.change(rest, tags)
      
    elif number >= 1000 and number < 1000000:
      tous = int(strNumber[:len(strNumber)-3])
      rest = strNumber[len(strNumber)-3:]

      corrFormTous = self.getCorrectForm(int(tous), tags) + " " + self.getCorrectForm(1000, tags) 
      return  corrFormTous + self.change(rest, tags)
      
    elif number == 1000000:
      return self.getCorrectForm(number, tags)
        

  def change(self, strNumber, tags):
    if self.isNumber(strNumber) == False:
      return strNumber

    number = float(strNumber)
    result = None

    if number < 20:
      result = self.getCorrectForm(strNumber, tags)
    elif number < 100:
      deci = strNumber[0]+"0"
      rest = strNumber[1]
      result = self.getFormFor(deci, rest, "0", tags)
    elif number < 1000:
      hund = strNumber[0]+"00"
      rest = strNumber[1:]
      result = self.getFormFor(hund, rest, "00", tags)
    
    if result == None:
      result = strNumber
    return result
  
  def getFormFor(self, base, rest, restPatter, tags):
    result = self.getCorrectForm(base, tags)
    #print result + " ; " + rest 
    if result != None and rest != restPatter:
      postfix = self.change(rest, tags)
      #print result + " ; " + rest + " ; " +postfix
      if postfix == None:
        result = None
      else:
        result = result + " " + postfix
    #else:
    #  result = None
    return result

  def getCorrectForm(self, number, tags):
    subject = self.getSubject(number, tags)
    tip = self.getTip(number, tags)
    result = None
    if subject != None and tip != None:
      result = subject + tip
    return result
    
  def splitTags(self, tags):
    return tags.split(":")

  def createAttributesDictionary(self, listOfTags):
    dictionary = {}
    for e in listOfTags:
        dictionary[ self.attributeNames[e] ] = e        
    return dictionary

  def getSubject(self, number, splittedTags):
    attributesDictionary = { 'base' : number, 
                              self.attributeNames[splittedTags[0]] : splittedTags[0] }
    return self.ruleManager.getSubjectFor(attributesDictionary)

  def getTip(self, number, splittedTags):
    attributesDictionary = self.createAttributesDictionary( splittedTags )
    attributesDictionary['base'] = number
    return self.ruleManager.getFlexFor(attributesDictionary)

  def getBaseForm(self, number, fleks="num"):
    return self.ruleManager.getBaseFor({'base':number, "fleks":fleks})
    
  def isNumber(self, string):
    try:
      float(string)
      return True
    except ValueError:
      return False

# ------------------------
if __name__ == "__main__":
  digit = input()
  nc = Numbers_changer()
  print nc.change(digit, "debug")

